fix(annotate_types): coerce bigquery date function arg types [CLAUDE]#7790
Merged
georgesittas merged 4 commits intoJun 24, 2026
Merged
Conversation
In BigQuery these functions return the type of their first argument. They were
annotated via `_annotate_by_args("this")` (`DATE_ADD`, `DATE_TRUNC`,
`DATETIME_TRUNC`, `TIMESTAMP_TRUNC`), which copies the first arg's type verbatim.
For a date/datetime string-literal first arg that type is the literal's `VARCHAR`,
so e.g. `DATE_ADD('2020-01-01', INTERVAL 1 DAY)` was annotated as `VARCHAR` instead
of `DATE`.
`DATE_SUB` was separately annotated via the base `_annotate_timeunit`, which handled
the string-literal case but mis-annotated a `TIMESTAMP` first arg as `DATETIME` (e.g.
`DATE_SUB(TIMESTAMP '...', INTERVAL 1 HOUR)` -> `DATETIME` instead of `TIMESTAMP`).
Route all five through a new bigquery `_annotate_date_func`: a typed first arg keeps
its exact type (via `_annotate_by_args`), and a string-literal first arg is coerced
to the function's own temporal type (`DATE_ADD`/`DATE_SUB`/`DATE_TRUNC` -> `DATE`,
`DATETIME_TRUNC` -> `DATETIME`, `TIMESTAMP_TRUNC` -> `TIMESTAMP`), matching
BigQuery's implicit coercion. Verified against BigQuery for the whole date/time
arithmetic family; the change is bigquery-only and does not affect other dialects.
Co-Authored-By: OpenCode google-vertex/claude-opus-4-8@default <noreply@opencode.ai>
georgesittas
approved these changes
Jun 24, 2026
georgesittas
left a comment
Collaborator
There was a problem hiding this comment.
Thank you, nice catch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In BigQuery these functions return the type of their first argument. They were annotated via
_annotate_by_args("this")(DATE_ADD,DATE_TRUNC,DATETIME_TRUNC,TIMESTAMP_TRUNC), which copies the first arg's type verbatim. For a date/datetime string-literal first arg that type is the literal'sVARCHAR, so e.g.DATE_ADD('2020-01-01', INTERVAL 1 DAY)was annotated asVARCHARinstead ofDATE.DATE_SUBwas separately annotated via the base_annotate_timeunit, which handled the string-literal case but mis-annotated aTIMESTAMPfirst arg asDATETIME(e.g.DATE_SUB(TIMESTAMP '...', INTERVAL 1 HOUR)->DATETIMEinstead ofTIMESTAMP).Route all five through a new bigquery
_annotate_date_func: a typed first arg keeps its exact type (via_annotate_by_args), and a string-literal first arg is coerced to the function's own temporal type (DATE_ADD/DATE_SUB/DATE_TRUNC->DATE,DATETIME_TRUNC->DATETIME,TIMESTAMP_TRUNC->TIMESTAMP), matching BigQuery's implicit coercion. Verified against BigQuery for the whole date/time arithmetic family; the change is bigquery-only and does not affect other dialects.